package main;

import main.exceptions.ElementException;

%%

%cup
%line
%column
%unicode
%class GameLexer


%{
	private String base1 = null;
	private String base2 = null;
	
	private void makeCombination(){
		Main.makeCombination(base1, base2);
		this.base1 = null;
		this.base2 = null;
	}
	
	private String fixName(String badName){
		String words[] = badName.split("\\s");
		String name = "";
		for(String s: words){
			if(!s.isEmpty()){
				name = name + " " + s;
			}
		}
		name = name.trim();
		return name;
	}
%}

%s ELEMENT1
%s ELEMENT2
%s TRAP

NEWLINE = \r|\n|\r\n
SPACE = [ \t\f]
WHITESPACE = {SPACE} | {NEWLINE}
PLUS = "+"
ANY = (. | NEWLINE)*
ALPHA = [:letter:]
WORD = {ALPHA}+

ELEMENT1 = ({WORD}{WHITESPACE}*)+
ELEMENT2 = ({WORD}{SPACE}*)+
COMBINATION = {ELEMENT1}{WHITESPACE}*{PLUS}{WHITESPACE}*{ELEMENT2}

%%

{COMBINATION} {
	System.out.println(yytext());
	String comb = yytext();
	String combinationElements[] = comb.split("\\x2b");
	base1 = fixName(combinationElements[0]);
	base2 = fixName(combinationElements[1]);
	makeCombination();
	}
	
{WHITESPACE} {
	/*Ignore white spaces*/
}

. {
	System.out.println("Error: Comando inv�lido(Fila: " + (yyline + 1) + " Columna: " + (yycolumn + 1) + ")");
	yybegin(TRAP);
}

<TRAP> {ANY} {
}